package com.community.process._1010.event.push;

import com.community.process._1010.common.api.CommonResult;
import com.community.process._1010.common.utils.ExternalApiUtils;
import com.community.process._1010.dao.entity.ProcessTOrder;
import com.community.process._1010.event.CancelOrderEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class CancelOrderPush {


    @Async
    @EventListener(classes = CancelOrderEvent.class)
    public void cancelOrderEvent(CancelOrderEvent event) {
        if (event.getOrder() != null) {
            ProcessTOrder order = event.getOrder();
            // 取消订单逻辑
            CommonResult<String> result = ExternalApiUtils.cancelOrder(order.getTradeNo(), event.getDto());
            if (result.getData() == null) {
                log.info("取消订单异常：{}，{}",order.getTradeNo(),result.getMsg());
            }
        }
    }
}
